package tal.cdm.gateway.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractNameValueGatewayFilterFactory;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.server.ServerWebExchange;


@Slf4j
public class PreLogGatewayFilterFactory extends AbstractNameValueGatewayFilterFactory{
    @Override
    public GatewayFilter apply(NameValueConfig config) {
        GatewayFilter gatewayFilter = (exchange, chain) -> {
            log.info("enter preLogGatewayFilter1....." + config.getName() + " " + config.getValue());
            ServerHttpRequest request = exchange.getRequest().mutate().build();
            ServerWebExchange modifiedRequest = exchange.mutate().request(request).build();
            return chain.filter(modifiedRequest);
        };
        return gatewayFilter;
    }
}
